﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace translator
{
    public class EditStringCommand : ICommand
    {
        MainWindow mainWindow;
        public EditStringCommand(MainWindow mainWindow)
        {
            this.mainWindow = mainWindow;
        }

        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }

        public bool CanExecute(object parameter)
        {
            if(mainWindow.Datagrid.SelectedIndex == -1) { return false; }
            return true;
        }

        public void Execute(object parameter)
        {
            ToEditString();
        }
        
        public void ToEditString()          //打开StringEdit窗口,并传递String参数
        {
            StringInfo tmp = mainWindow.Datagrid.SelectedItem as StringInfo;
            mainWindow.EditingStringIndex = mainWindow.Datagrid.SelectedIndex;
            if (mainWindow.stringEditWindow == null) { mainWindow.stringEditWindow = new StringEditWindow(mainWindow); }
            mainWindow.stringEditWindow.EditString(mainWindow.GetHint(tmp.Original), tmp.Original, tmp.Translated, tmp.Sid);
        }

    }
}
